package vip.wangwenhao.page;

import java.io.Serializable;
import java.util.List;

/**
 * @author wangwenhao
 * @param <T>
 */
public class PageResult<T> implements Serializable {
    private static final long serialVersionUID = -300455228475131963L;

    private Integer pageNo;
    private Integer pageSize;
    private Long totalCount;
    private List<T> data;
    private Boolean success;
    private String message;

    public PageResult() {
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static <T> PageResult<T> success(List<T> t, Long totalCount){
        PageResult<T> result = new PageResult<>();
        result.setData(t);
        result.setTotalCount(totalCount);
        result.setSuccess(true);
        return result;
    }

    public static <T> PageResult<T> success(List<T> t, Long totalCount, Integer pageNo, Integer pageSize){
        PageResult<T> result = new PageResult<>();
        result.setData(t);
        result.setTotalCount(totalCount);
        result.setPageNo(pageNo);
        result.setPageSize(pageSize);
        result.setSuccess(true);
        return result;
    }

    public static <T> PageResult<T> fail(){
        PageResult<T> result = new PageResult<>();
        result.setSuccess(false);
        return result;
    }

}